<div class="box_right">
	<h1>
		已发布发改委价
		<span style="float: right;font-size: 14px;padding-top: 20px;"><?php echo $model[0]->create_time;?>生效 钉铛后台发布</span>
	</h1>
	<div class="pro_box">
		<ul class="price">
		<?php if (isset($model)){
		    foreach ($model as $val){?>
			<li>
				<b><?php echo $val->glmodel_name;?></b>
				<p>发改委价格</p>
				<span>￥<?php echo $val->sc_price;?></span>
			</li>
		<?php }}?>
			<div class="clear"></div>
		</ul>
			  
	  <div class="order_list">
	  	<div class="layui-row">
	  		<div class="layui-col-xs4">
	  			<h2 class="order_list_h">挂牌价调整</h2>
	  		</div>
	  		<div class="layui-col-xs1 layui-col-xs-offset7">
	  			<?php if (in_array('gasstation/gasolinemodel/add_gasolinemodel', $_SESSION['GASSTATION_ACL_ARR'])){?>
            	<a class="btn_get" href="<?php echo base_url()."gasstation/gasolinemodel/log"?>" style="background: #02A3FE;padding:5px 10px;">修改记录</a>
            	<?php }?>
	  		</div>
	  	</div>
	  	
		<table class="layui-table ct" lay-skin="line">
		  <thead>
		    <tr >
		      <th>油品名称</th>
		      <th>挂牌价格</th>
              <?php if(!empty($has_gas_mem)):?><th>会员日降幅</th><?php endif;?>
		      <th>降幅(私家车)</th>
              <th>降幅(网约车)</th>
		      <th>生效日期</th>
		      <th>预约发布</th>
		      <th>操作</th>
		    </tr> 
		  </thead>
		  <tbody>
		  	<?php if (isset($result)&&count($result)>0){
					foreach ($result as $gasolinemodel){
			?>
		    <tr>
		      <td><span id="yh_<?php echo $gasolinemodel->id;?>" name="yh"><?php echo $gasolinemodel->glmodel_name;?></span></td>
		      
		      <td>￥ <?php echo $gasolinemodel->yz_price_value;?></td>
              <?php if(!empty($has_gas_mem)):?><td>￥ - <?php echo $gasolinemodel->gasmember_yz_price_decline;?></td><?php endif;?>
		      <td>￥ - <?php echo $gasolinemodel->yz_decline_price_value;?></td>
		      <td>￥ - <?php echo $gasolinemodel->net_decline_price_value;?></td>
			  <td>
			  <?php if (isset($gasolinemodel->old_effective_time)) {?>
			  <?php echo $gasolinemodel->old_effective_time;?>
			  <?php }else{?>
			     无
			  <?php }?>
			  </td>
			  <td>
			 
			  
			  <input id="sc_price_<?php echo $gasolinemodel->id;?>" name="sc_price" type="hidden" value="<?php if (isset($gasolinemodel->sc_price)) echo $gasolinemodel->sc_price;?>">
			  
			  <?php if ($gasolinemodel->is_effective == 1){ ?>
			    价格:￥ <?php echo $gasolinemodel->next_yz_price_value;?> <br/>
                私家:￥ - <?php echo $gasolinemodel->next_yz_decline_price_value;?><br/>
                网约:￥ - <?php echo $gasolinemodel->next_net_decline_price_value;?><br/>
				<?php if (isset($gasolinemodel->effective_time)) echo $gasolinemodel->effective_time;?>
			  <?php }else{?>
			    无
			  <?php }?>
			  </td>
			  <td>
			 <?php if ($gasolinemodel->is_effective == 1){?>
			 <a href="javascript:void(0)" onclick="chexiao('<?php echo $gasolinemodel->id;?>')" data-toggle="modal" class="btn btn_get">撤销</a>
			 <?php }else{?>
			 <a href="javascript:void(0)" onclick="effective('<?php echo $gasolinemodel->id;?>',<?php echo $gasolinemodel->temp_yz_price;?>,<?php echo $gasolinemodel->temp_yz_decline_price;?>,<?php echo $gasolinemodel->temp_net_decline_price;?>)" data-toggle="modal" class="btn btn_get" style="background: #F18101;">修改</a>
			 <?php }?>
             <a href="javascript:void(0)" onclick="gasmember('<?php echo $gasolinemodel->gm_id;?>')" data-toggle="modal" class="btn btn_get" style="background: #F18101;">会员日</a>
			  </td>
		    </tr>
			<?php 	}
				}else{?>
			<tr>
			  <td colspan="12">无数据</td>
			</tr>
			<?php }?>
		  </tbody>
		</table>
	  </div>
	  <div class="col-sm-12">
		<div class="modal-footer no-margin-top">
			<div class="pull-left record">
				共<?php echo $count;?>条记录
				</div>
            	<?php if (isset($page))echo $page;?>
		</div>
	  </div> 
	</div>
</div>

<div id="chexiaoP" class="modal fade" role="dialog" aria-hidden="true">
	<div class="modal-dialog" style="width: 300px">
		<div class="modal-content">
			<div class="modal-header">
			  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
			  <h3>提示信息</h3>
			</div>
			<div class="modal-body">
			  <p>确定要撤销吗？</p>
			</div>
			<div class="modal-footer">
			  <a id="cxbtn" href="#" class="btn btn-danger">确定</a>
			  <a href="#" class="btn btn-info" data-dismiss="modal" aria-hidden="true">取消</a>
			</div>
		</div>
	</div>
</div>

<div id="effectiveP" class="modal fade" role="dialog" aria-hidden="true">
  <form id="usrform" role="form" action="<?php echo base_url().'gasstation/gasolinemodel/eff_gasolinemodel/';?>" method="post" onsubmit="return check()">
  <input id="gm_id" name="gm_id" type="hidden" value="">
  <input id="sc_price" name="sc_price" type="hidden" value="">
  <input id="date_old" name="date_old" type="hidden"  value="">
	<div class="modal-dialog" style="width: 700px">
		<div class="modal-content">
			<div class="modal-header">
			  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
			  <h3>油价修改</h3><br/>
			  <span id="yh" name="yh"></span>
		</div>
			<div class="modal-body">
			  <table class="layui-table ct" lay-skin="line">
		  		<thead>
					<tr>
						<th>挂牌价</th>
                        <th>私家车降幅</th>
                        <th>网约车降幅</th>
						<th>生效日期</th>
						
					</tr>
		 		</thead>
		  	  <tbody>
				<tr>
					<td><input id="yz_price" name="yz_price" type="text" class="layui-input" style="width: 150px" value="" datatype="*" nullmsg="请输入挂牌价！"></td>
					<td><input id="yz_decline_price" name="yz_decline_price" type="text" class="layui-input" style="width: 60px"  value="" datatype="*" nullmsg="请输入降幅！"></td>
                    <td><input id="net_decline_price" name="net_decline_price" type="text" class="layui-input" style="width: 60px"value="" datatype="*" nullmsg="请输入降幅！"></td>
                    
					<td><input id="date" name="date" type="text" class="layui-input" placeholder="年-月-日 时:分:秒" value="<?php echo date('Y-m-d H:i:s');?>"></td>
				</tr>
		  	  </tbody>
			</table>
			</div>
			<div class="modal-footer">
			<button id="btnSubmit" class="btn btn-get" type="submit" style="background: #F18101;color:#FFFFFF;position:relative;left:-45%;padding: 5px 20px;">确定</button>
			</div>
		</div>
	</div>
	</form>
</div>



<div id="gasmember"  class="modal fade"  role="dialog" aria-hidden="true">
  <form id="usrform" role="form" action="<?php echo base_url().'gasstation/gasolinemodel/gas_member_save/';?>" method="post">

	<div class="modal-dialog" style="width: 700px">
		<div class="modal-content">
			<div class="modal-header">
			  <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
			  <h3>油站会员日价格</h3><br/>
			  <span id="yh" name="yh"></span>
		</div>
			<div class="modal-body" id="gasmember_div">
			  

			</div>
			<div class="modal-footer">
			<button id="btnSubmit" class="btn btn-get" type="submit" style="background: #F18101;color:#FFFFFF;position:relative;left:-45%;padding: 5px 20px;">确定</button>
			</div>
		</div>
	</div>
	</form>
</div>

<script>
//Demo
layui.use(['form','element','laydate'], function(){
  var form = layui.form,
  	element = layui.element,
  	laydate = layui.laydate;
  
  //监听提交
  form.on('submit(formDemo)', function(data){
    layer.msg(JSON.stringify(data.field));
    return false;
  });
});


</script>
<script type="text/javascript">
layui.use(['form','element','laydate'], function(){
	  var form = layui.form,
	  	element = layui.element,
	  	laydate = layui.laydate;

		  	  //时间选择器
		  	  laydate.render({
		  	    elem: '#date'
		  	    ,type: 'datetime'
		  	  });
	  
	  //监听提交
	  form.on('submit(formDemo)', function(data){
	    layer.msg(JSON.stringify(data.field));
	    return false;
	  });
	});

function chexiao(id) {
	
	$("#cxbtn").attr('href','<?php echo base_url().'gasstation/gasolinemodel/cx_gasolinemodel/'?>'+id);
    $('#chexiaoP').modal('show');
	
}

function effective(id,temp_yz_price,temp_yz_decline_price,temp_net_decline_price){

 	var date = $("#date_"+id).val();
 	var sc_price = $("#sc_price_"+id).val();
 	var cont = document.getElementById("yh_"+id).innerText;

	$("#gm_id").get(0).value = id;
	$("#date_old").get(0).value = date;
	$("#yh").get(0).value = date;
	$("#sc_price").get(0).value = sc_price;
	
	$('#yz_price').val(temp_yz_price);
	$('#yz_decline_price').val(temp_yz_decline_price);
	$('#net_decline_price').val(temp_net_decline_price);

	document.getElementById("yh").innerText = cont;
	
    $('#effectiveP').modal('show');
}

function gasmember(id){
	
	$.ajax({
	   type: "POST",
	   url:' <?php echo base_url()?>gasstation/gasolinemodel/get_gas_member_info/',
	   data: "id="+id,
	   success: function(msg){
		 $('#gasmember_div').html(msg);
		 $('#gasmember').modal('show');
	   }
	});
	
    
}

function check(){

 	var yz_price = $("#yz_price").val();
 	var sc_price = $("#sc_price").val();
 	var yz_decline_price = $("#yz_decline_price").val();
 	var date = $("#date").val();

	if (yz_price == '') {
	alert('请输入挂牌价');
	return false;
	}

	if (!isNumber(yz_price)) {
	alert('挂牌价错误');
	return false;
	}

	if (eval(yz_price) > eval(sc_price)) {
	alert('油站价应低于发改委油价(￥'+sc_price+')');
	return false;
	}

	if (yz_decline_price == '') {
		alert('请输入降幅');
		return false;
	}

	if (!isNumber(yz_decline_price)) {
		alert('降幅错误');
		return false;
	}

	if (eval(yz_decline_price) > eval(yz_price)) {
		alert('降幅应低于挂牌价');
		return false;
	}

	if (contrastTime(date)) {
		alert('发布时间应大于当前时间');
		return false;
	}
	
	return true;
}

function isNumber(val){

    var regPos = /^\d+(\.\d+)?$/;
    var regNeg = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/;
    if(regPos.test(val) || regNeg.test(val)){
        return true;
    }else{
        return false;
    }
}

function contrastTime(start) {  
	 var myDate = new Date();
     var now = myDate.valueOf();
     var time = new Date(start).valueOf();
     if(now > time){
       return true;
     } else {
       return false;
     }
}

</script>